package com.jy.adscm.operation.aftersales.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.aftersales.bean.QueryShCustomerInfo;
import com.jy.adscm.operation.aftersales.bean.ShCustomerInfo;
import com.jy.adscm.operation.aftersales.mapper.mysql.ShCustomerInfoMapper;
import com.jy.adscm.operation.aftersales.service.ShCustomerInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-07-03
 */
@Service
public class ShCustomerInfoServiceImpl extends ServiceImpl<ShCustomerInfoMapper, ShCustomerInfo> implements ShCustomerInfoService {
@Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Page<ShCustomerInfo> selectAll(Page<ShCustomerInfo> page, QueryShCustomerInfo queryShCustomerInfo) {
        Wrapper<ShCustomerInfo> wrapper =new EntityWrapper<>();
    if (AdscmBaseUtils.getInstance().isNotEmpty(queryShCustomerInfo.getName(),null)){
        wrapper.like("name",queryShCustomerInfo.getName());
      }
       page = super.selectPage(page, wrapper);
        List<ShCustomerInfo> records = page.getRecords();
        for (ShCustomerInfo shCustomerInfo : records) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(shCustomerInfo.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(shCustomerInfo.getCreator());
                shCustomerInfo.setCreatorName(jyUser.getName());
            }
        }
        page.setTotal(super.selectCount(wrapper));
        return page;
    }

    @Override
    public List<ShCustomerInfo> selectByName(String name) {
        Wrapper<ShCustomerInfo> wrapper=new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(name,null)){
            wrapper.like("name",name);
        }
        List<ShCustomerInfo> shCustomerInfos = super.selectList(wrapper);
        return shCustomerInfos;
    }
}
